﻿Namespace Commands

    Partial Class GetShareItems
        Private Class GetMovies
            Friend Shared Function GetReply(ByVal share As Entities.Share, ByVal directoryCode As String) As Reply
                Dim clsRet As Reply = Nothing
                If String.IsNullOrEmpty(directoryCode) Or directoryCode = "\" Then
                    clsRet = CreateReplyObject(True)
                    Dim clsGroup As New Group("Shared Item Filters")
                    clsRet.Groups.Add(clsGroup)
                    clsGroup.Directories.Add(New Directory("\All", "All", "All movies in alphabetical order"))
                    clsGroup.Directories.Add(New Directory("\NewLast7Days", "Recent Additions (7 days)", "New movies during the last week"))
                    clsGroup.Directories.Add(New Directory("\NewLast31Days", "Recent Additions (31 days)", "New movies during the last month"))
                    clsGroup.Directories.Add(New Directory("\FileSys", "Browse by path", "Browses movies in the hierarcical structure at your buddy"))

                    Dim clsGroup2 As New Group("Movie Information Filters")
                    clsRet.Groups.Add(clsGroup2)
                    clsGroup2.Directories.Add(New Directory("\Genres", "By genres", "Movies by genre in order of relevance"))
                    clsGroup2.Directories.Add(New Directory("\GenreAnywhere", "By genre anywhere", "Movies with genre of any relevance"))
                    clsGroup2.Directories.Add(New Directory("\Certification", "By certification", "Show by certification, such as PG"))
                    clsGroup2.Directories.Add(New Directory("\Cast", "By actor/acress", "Find movies with a particular actor/actress"))
                    clsGroup2.Directories.Add(New Directory("\Director", "By director", "Find movies by director"))
                    clsGroup2.Directories.Add(New Directory("\Writer", "By writer", "Find movies by writer"))

                    Dim clsGroup3 As New Group("Media Information Filters")
                    clsRet.Groups.Add(clsGroup3)
                    clsGroup3.Directories.Add(New Directory("\PicSize", "By picture size", "Movies sorted by video picture size"))
                    clsGroup3.Directories.Add(New Directory("\AudioLanguages", "By audio language", "Movies sorted by audio language"))

                ElseIf Not directoryCode.StartsWith("\"c) Then
                    clsRet = CreateReplyObject(True)
                    'erranous directory, must start with "\"
                Else
                    Dim aParts() As String = directoryCode.Substring(1).Split("\"c)
                    Select Case aParts(0).ToLower
                        Case "genres"
                            clsRet = GetByGenres(share, directoryCode, aParts)
                        Case "genreanywhere"
                            clsRet = GetByGenreAnywhere(share, directoryCode, aParts)
                        Case "certification"
                            clsRet = GetByCertification(share, directoryCode, aParts)
                        Case "cast"
                            clsRet = GetByCast(share, directoryCode, aParts)
                        Case "director"
                            clsRet = GetByDirector(share, directoryCode, aParts)
                        Case "writer"
                            clsRet = GetByWriter(share, directoryCode, aParts)
                        Case "all"
                            clsRet = GetAll(share, directoryCode, aParts, DateTime.MinValue)
                        Case "newlast7days"
                            clsRet = GetAll(share, directoryCode, aParts, Now.ToUniversalTime.Subtract(TimeSpan.FromDays(7)))
                        Case "newlast31days"
                            clsRet = GetAll(share, directoryCode, aParts, Now.ToUniversalTime.Subtract(TimeSpan.FromDays(31)))
                        Case "filesys"
                            clsRet = GetByFileSys(share, directoryCode, aParts, DateTime.MinValue)
                        Case "picsize"
                            clsRet = GetByPictureSize(share, directoryCode, aParts)
                        Case "audiolanguages"
                            clsRet = GetByAudioLanguages(share, directoryCode, aParts)
                        Case Else
                            clsRet = New Reply
                    End Select
                End If
                Return clsRet
            End Function
            Private Shared Function CreateReplyObject(ByVal forFilters As Boolean) As Reply
                Dim clsRet As New Reply
                If forFilters Then
                    clsRet.Columns.Add(New Column("Name", 100, Column.HorizontalAlignment.Left))
                    clsRet.Columns.Add(New Column("Description", 250, Column.HorizontalAlignment.Left))
                Else
                    clsRet.Columns.Add(New Column("Name", 120, Column.HorizontalAlignment.Left))
                    clsRet.Columns.Add(New Column("Size", 60, Column.HorizontalAlignment.Right))
                    clsRet.Columns.Add(New Column("Genres", 80, Column.HorizontalAlignment.Left))
                    clsRet.Columns.Add(New Column("Video", 100, Column.HorizontalAlignment.Left))
                    clsRet.Columns.Add(New Column("Audio", 100, Column.HorizontalAlignment.Left))
                    clsRet.Columns.Add(New Column("Subtitles", 100, Column.HorizontalAlignment.Left))
                    clsRet.Columns.Add(New Column("Year", 40, Column.HorizontalAlignment.Right))
                    clsRet.Columns.Add(New Column("Runtime", 50, Column.HorizontalAlignment.Right))
                    clsRet.Columns.Add(New Column("Added", 70, Column.HorizontalAlignment.Left))
                End If
                Return clsRet
            End Function

            Private Shared Function ConvertToItemInfos(ByVal items As Generic.List(Of Entities.SharedItem)) As Generic.List(Of ItemInfo)
                Dim aMediaInfos As New Generic.Dictionary(Of Integer, Entities.MediaInfo)
                For Each clsItem As Entities.SharedItem In items
                    aMediaInfos.Add(clsItem.Id, EntityHandlers.MediaInfo.GetBySharedItemId(clsItem.Id))
                Next
                Return ConvertToItemInfos_Worker(items, aMediaInfos)
            End Function
            Private Shared Function ConvertToItemInfos(ByVal mediaInfos As Generic.List(Of Entities.MediaInfo)) As Generic.List(Of ItemInfo)
                Dim aItems As New Generic.List(Of Entities.SharedItem)
                Dim aMediaInfos As New Generic.Dictionary(Of Integer, Entities.MediaInfo)
                For Each clsMI As Entities.MediaInfo In mediaInfos
                    aMediaInfos.Add(clsMI.SharedItemId, clsMI)
                    Dim clsItem As Entities.SharedItem = EntityHandlers.SharedItems.GetById(clsMI.SharedItemId)
                    aItems.Add(clsItem)
                Next
                Return ConvertToItemInfos_Worker(aItems, aMediaInfos)
            End Function

            Private Shared Function ConvertToItemInfos_Worker(ByVal items As Generic.List(Of Entities.SharedItem), ByVal mediaInfos As Generic.Dictionary(Of Integer, Entities.MediaInfo)) As Generic.List(Of ItemInfo)
                Dim aRet As New Generic.List(Of ItemInfo)
                For Each clsItem As Entities.SharedItem In items
                    Dim clsMI As Entities.MediaInfo = mediaInfos.Item(clsItem.Id)

                    Dim clsII As New ItemInfo
                    clsII.Name = clsItem.Name
                    clsII.Type = clsItem.ItemType
                    clsII.Id = clsItem.Id
                    clsII.UniqueId = clsItem.UniqueId
                    clsII.ExternalIds = Handler_MediaInfo.GetFeatureIds(clsMI)
                    clsII.Cells.Add(New CellString(Handler_MediaInfo.GetFeatureTitle(clsMI, clsItem.Name)))
                    clsII.Cells.Add(New CellFileSize(clsItem.TotalSize))
                    clsII.Cells.Add(New CellString(Handler_MediaInfo.GetGenresInfo(clsMI)))
                    clsII.Cells.Add(New CellString(Handler_MediaInfo.GetVideoInfo(clsMI)))
                    clsII.Cells.Add(New CellString(Handler_MediaInfo.GetAudioInfo(clsMI)))
                    clsII.Cells.Add(New CellString(Handler_MediaInfo.GetSubtitlesInfo(clsMI)))
                    clsII.Cells.Add(New CellString(Handler_MediaInfo.GetYear(clsMI)))
                    clsII.Cells.Add(New CellString(Handler_MediaInfo.GetRuntimeInfo(clsMI)))
                    clsII.Cells.Add(New CellDate(clsItem.Added))
                    aRet.Add(clsII)
                Next
                Return aRet
            End Function

            Private Shared Function GetByCertification(ByVal share As Entities.Share, ByVal directoryCode As String, ByVal parts() As String) As Reply
                Dim clsRet As Reply = CreateReplyObject(False)

                If parts.Length = 1 Then 'return list of countries/regions
                    Dim clsGroup As New Group("Certification Countries")
                    clsRet.Groups.Add(clsGroup)
                    For Each strCountry As String In EntityHandlers.MediaInfo.GetAllCertificationCountriesByShareId(share.Id)
                        clsGroup.Directories.Add(New Directory(String.Format("{0}\{1}", directoryCode, strCountry), strCountry))
                    Next
                ElseIf parts.Length = 2 Then 'return list of certifications for the selected country
                    Dim strCountry As String = parts(1)
                    Dim clsGroup As New Group(String.Format("Certification Levels for {0}", strCountry))
                    clsRet.Groups.Add(clsGroup)
                    For Each strLevel As String In EntityHandlers.MediaInfo.GetCertificationsByShareIdAndCountry(share.Id, strCountry)
                        clsGroup.Directories.Add(New Directory(String.Format("{0}\{1}", directoryCode, strLevel), strLevel))
                    Next
                ElseIf parts.Length = 3 Then
                    Dim strCountry As String = parts(1)
                    Dim strLevel As String = parts(2)

                    Dim clsGroup2 As New Group(String.Format("Movies with certification level {0} in {1}", strLevel, strCountry))
                    clsRet.Groups.Add(clsGroup2)
                    Dim aMediaInfos As Generic.List(Of Entities.MediaInfo)
                    aMediaInfos = EntityHandlers.MediaInfo.GetAllByShareIdAndCertification(share.Id, strCountry, strLevel)
                    clsGroup2.Items = ConvertToItemInfos(aMediaInfos)
                End If
                If parts.Length > 1 Then
                End If
                Return clsRet
            End Function

            Private Shared Function GetByCast(ByVal share As Entities.Share, ByVal directoryCode As String, ByVal parts() As String) As Reply
                Dim clsRet As Reply = CreateReplyObject(False)

                If parts.Length = 1 Then 'return list of countries/regions
                    Dim clsGroup As New Group("Actors")
                    clsRet.Groups.Add(clsGroup)
                    For Each strName As String In EntityHandlers.MediaInfo.GetAllActorsByShareId(share.Id)
                        clsGroup.Directories.Add(New Directory(String.Format("{0}\{1}", directoryCode, strName), strName))
                    Next
                ElseIf parts.Length = 2 Then
                    Dim strName As String = parts(1)

                    Dim clsGroup2 As New Group(String.Format("Movies with actor {0}", strName))
                    clsRet.Groups.Add(clsGroup2)
                    Dim aMediaInfos As Generic.List(Of Entities.MediaInfo)
                    aMediaInfos = EntityHandlers.MediaInfo.GetAllByShareIdAndActor(share.Id, strName)
                    clsGroup2.Items = ConvertToItemInfos(aMediaInfos)
                End If
                If parts.Length > 1 Then
                End If
                Return clsRet
            End Function

            Private Shared Function GetByDirector(ByVal share As Entities.Share, ByVal directoryCode As String, ByVal parts() As String) As Reply
                Dim clsRet As Reply = CreateReplyObject(False)

                If parts.Length = 1 Then 'return list of countries/regions
                    Dim clsGroup As New Group("Directors")
                    clsRet.Groups.Add(clsGroup)
                    For Each strName As String In EntityHandlers.MediaInfo.GetAllDirectorsByShareId(share.Id)
                        clsGroup.Directories.Add(New Directory(String.Format("{0}\{1}", directoryCode, strName), strName))
                    Next
                ElseIf parts.Length = 2 Then
                    Dim strName As String = parts(1)

                    Dim clsGroup2 As New Group(String.Format("Movies by director {0}", strName))
                    clsRet.Groups.Add(clsGroup2)
                    Dim aMediaInfos As Generic.List(Of Entities.MediaInfo)
                    aMediaInfos = EntityHandlers.MediaInfo.GetAllByShareIdAndDirector(share.Id, strName)
                    clsGroup2.Items = ConvertToItemInfos(aMediaInfos)
                End If
                If parts.Length > 1 Then
                End If
                Return clsRet
            End Function

            Private Shared Function GetByWriter(ByVal share As Entities.Share, ByVal directoryCode As String, ByVal parts() As String) As Reply
                Dim clsRet As Reply = CreateReplyObject(False)

                If parts.Length = 1 Then 'return list of countries/regions
                    Dim clsGroup As New Group("Directors")
                    clsRet.Groups.Add(clsGroup)
                    For Each strName As String In EntityHandlers.MediaInfo.GetAllWritersByShareId(share.Id)
                        clsGroup.Directories.Add(New Directory(String.Format("{0}\{1}", directoryCode, strName), strName))
                    Next
                ElseIf parts.Length = 2 Then
                    Dim strName As String = parts(1)

                    Dim clsGroup2 As New Group(String.Format("Movies with story by writer {0}", strName))
                    clsRet.Groups.Add(clsGroup2)
                    Dim aMediaInfos As Generic.List(Of Entities.MediaInfo)
                    aMediaInfos = EntityHandlers.MediaInfo.GetAllByShareIdAndWriter(share.Id, strName)
                    clsGroup2.Items = ConvertToItemInfos(aMediaInfos)
                End If
                If parts.Length > 1 Then
                End If
                Return clsRet
            End Function

            Private Shared Function GetByGenreAnywhere(ByVal share As Entities.Share, ByVal directoryCode As String, ByVal parts() As String) As Reply
                Dim clsRet As Reply = CreateReplyObject(False)

                If parts.Length > 1 AndAlso parts(1) = "Uncategorized" Then
                    Dim clsGroup As New Group("Uncategorized movies")
                    clsRet.Groups.Add(clsGroup)
                    clsGroup.Items = ConvertToItemInfos(EntityHandlers.SharedItems.GetAllByItemTypeAndMissingGenres(Entities.ItemType.Movies))
                Else
                    Dim aWith As New Generic.List(Of String)
                    For i As Integer = 1 To parts.Count - 1
                        aWith.Add(parts(i))
                    Next

                    Dim aGenres As New Generic.List(Of String)
                    aGenres = EntityHandlers.MediaInfo.GetAllGenresByShareId(share.Id, aWith.ToArray)
                    Dim clsGroup As New Group("Genres")
                    clsRet.Groups.Add(clsGroup)
                    If parts.Length = 1 Then
                        Dim strDirCode As String = String.Format("{0}\{1}", directoryCode, "Uncategorized")
                        clsGroup.Directories.Add(New Directory(strDirCode, "[Uncategorized]"))
                    End If
                    For Each strGenre As String In aGenres
                        Dim strName As String = Framework.Misc.ToAndList(aWith, strGenre)
                        clsGroup.Directories.Add(New Directory(String.Format("{0}\{1}", directoryCode, strGenre), strName))
                    Next
                    If parts.Length > 1 Then
                        Dim clsGroup2 As New Group("Movies with genres " & Framework.Misc.ToAndList(aWith))
                        clsRet.Groups.Add(clsGroup2)
                        Dim aMediaInfos As Generic.List(Of Entities.MediaInfo)
                        aMediaInfos = EntityHandlers.MediaInfo.GetAllByShareIdAndWithGenres(share.Id, aWith.ToArray)
                        clsGroup2.Items = ConvertToItemInfos(aMediaInfos)
                    End If
                End If
                Return clsRet
            End Function

            Private Shared Function GetByGenres(ByVal share As Entities.Share, ByVal directoryCode As String, ByVal parts() As String) As Reply
                Dim clsRet As Reply = CreateReplyObject(False)

                If parts.Length > 1 AndAlso parts(1) = "Uncategorized" Then
                    Dim clsGroup As New Group("Uncategorized movies")
                    clsRet.Groups.Add(clsGroup)
                    clsGroup.Items = ConvertToItemInfos(EntityHandlers.SharedItems.GetAllByItemTypeAndMissingGenres(Entities.ItemType.Movies))
                Else
                    Dim aWith As New Generic.List(Of String)
                    For i As Integer = 1 To parts.Count - 1
                        aWith.Add(parts(i))
                    Next

                    Dim aGenres As Generic.List(Of String)
                    aGenres = EntityHandlers.MediaInfo.GetAllSubGenresByShareId(share.Id, aWith)

                    Dim clsGroup As New Group("Genres")
                    clsRet.Groups.Add(clsGroup)
                    If parts.Length = 1 Then
                        Dim strDirCode As String = String.Format("{0}\{1}", directoryCode, "Uncategorized")
                        clsGroup.Directories.Add(New Directory(strDirCode, "[Uncategorized]"))
                    End If
                    For Each strGenre As String In aGenres
                        Dim strName As String = Framework.Misc.ToAndList(aWith, strGenre, "any")
                        clsGroup.Directories.Add(New Directory(String.Format("{0}\{1}", directoryCode, strGenre), strName))
                    Next
                    If parts.Length > 1 Then
                        Dim clsGroup2 As New Group("Movies in genre " & Framework.Misc.ToAndList(aWith, "any"))
                        clsRet.Groups.Add(clsGroup2)
                        Dim aMediaInfos As Generic.List(Of Entities.MediaInfo)
                        aMediaInfos = EntityHandlers.MediaInfo.GetAllByShareIdAndInGenre(share.Id, aWith)
                        clsGroup2.Items = ConvertToItemInfos(aMediaInfos)
                    End If
                End If
                Return clsRet
            End Function

            Private Shared Function GetByPictureSize(ByVal share As Entities.Share, ByVal directoryCode As String, ByVal parts() As String) As Reply
                Dim clsRet As Reply

                If parts.Length = 1 Then 'return list of width groupings
                    clsRet = CreateReplyObject(True)
                    Dim clsGroup As New Group("Picture width groupings")
                    clsRet.Groups.Add(clsGroup)

                    Dim aMovieSizes As Generic.List(Of Entities.Size)
                    aMovieSizes = EntityHandlers.MediaInfo.GetAllMoviePictureSizesByShareId(share.Id)

                    Dim blnHasLoRes As Boolean = False
                    Dim blnHasDVDRes As Boolean = False
                    Dim blnHasHDRes As Boolean = False
                    Dim blnHasFullHDRes As Boolean = False
                    For Each clsSize As Entities.Size In aMovieSizes
                        If clsSize.Width < 720 - 20 Then
                            blnHasLoRes = True
                        ElseIf clsSize.Width < 1280 - 30 Then
                            blnHasDVDRes = True
                        ElseIf clsSize.Width < 1920 - 40 Then
                            blnHasHDRes = True
                        Else
                            blnHasFullHDRes = True
                        End If
                    Next
                    If blnHasLoRes Then
                        clsGroup.Directories.Add(New Directory(String.Format("{0}\{1}", directoryCode, "LoRes"), "Low resolution", "Movies with a picture width less than 700 pixels"))
                    End If
                    If blnHasDVDRes Then
                        clsGroup.Directories.Add(New Directory(String.Format("{0}\{1}", directoryCode, "DVD"), "DVD resolution", "Movies with a picture width from 700 to 1250 pixels"))
                    End If
                    If blnHasHDRes Then
                        clsGroup.Directories.Add(New Directory(String.Format("{0}\{1}", directoryCode, "HD"), "HD resolution", "Movies with a picture width from 1250 to 1940 pixels (720p/i)"))
                    End If
                    If blnHasFullHDRes Then
                        clsGroup.Directories.Add(New Directory(String.Format("{0}\{1}", directoryCode, "FullHD"), "FullHD resolution", "Movies with a picture over 1940 pixels (1080p/i)"))
                    End If
                Else
                    Dim iMinWidth As Short, iMaxWidth As Short, strName As String
                    Select Case parts(1).ToLower
                        Case "lores"
                            iMinWidth = 0 : iMaxWidth = 699 : strName = "Low resolution movies"
                        Case "dvd"
                            iMinWidth = 699 : iMaxWidth = 1249 : strName = "DVD movies"
                        Case "hd"
                            iMinWidth = 1250 : iMaxWidth = 1939 : strName = "HD movies"
                        Case "fullhd"
                            iMinWidth = 1940 : iMaxWidth = Short.MaxValue : strName = "Full HD movies"
                        Case Else
                            iMinWidth = -1 : iMaxWidth = -1 : strName = String.Empty
                    End Select

                    clsRet = CreateReplyObject(False)

                    Dim clsGroup2 As New Group(strName)
                    clsRet.Groups.Add(clsGroup2)
                    Dim aMediaInfos As Generic.List(Of Entities.MediaInfo)
                    aMediaInfos = EntityHandlers.MediaInfo.GetAllByShareIdAndSize(share.Id, iMinWidth, iMaxWidth)
                    clsGroup2.Items = ConvertToItemInfos(aMediaInfos)
                End If
                Return clsRet
            End Function
            Private Shared Function GetByAudioLanguages(ByVal share As Entities.Share, ByVal directoryCode As String, ByVal parts() As String) As Reply
                Dim clsRet As Reply

                If parts.Length = 1 Then 'return list of width groupings
                    clsRet = CreateReplyObject(True)
                    Dim clsGroup As New Group("Audio language")
                    clsRet.Groups.Add(clsGroup)

                    Dim aLanguages As Generic.List(Of String)
                    aLanguages = EntityHandlers.MediaInfo.GetAllAudioLanguagesByShareId(share.Id)

                    For Each strLanguage As String In aLanguages
                        If strLanguage IsNot Nothing AndAlso strLanguage.Trim.Length > 0 Then
                            clsGroup.Directories.Add(New Directory(String.Format("{0}\{1}", directoryCode, strLanguage), strLanguage, String.Format("Movies with one or more audiotracks in {0}", strLanguage)))
                        End If
                    Next
                Else
                    clsRet = CreateReplyObject(False)
                    Dim strLanguage As String = parts(1)

                    Dim clsGroup2 As New Group(strLanguage)
                    clsRet.Groups.Add(clsGroup2)
                    Dim aMediaInfos As Generic.List(Of Entities.MediaInfo)
                    aMediaInfos = EntityHandlers.MediaInfo.GetAllByShareIdAndAudioLanguage(share.Id, strLanguage)
                    clsGroup2.Items = ConvertToItemInfos(aMediaInfos)
                End If
                Return clsRet
            End Function


            Private Shared Function ConcatArrayToDirectory(ByVal array As Generic.List(Of String)) As String
                Dim clsSb As New System.Text.StringBuilder
                For Each strItem As String In array
                    If clsSb.Length > 0 Then clsSb.Append("\"c)
                    clsSb.Append(strItem)
                Next
                Return clsSb.ToString
            End Function
            Private Shared Function ConcatArrayToDirectory(ByVal array() As String, ByVal start As Integer) As String
                Dim clsSb As New System.Text.StringBuilder
                For i As Integer = start To array.Length - 1
                    If clsSb.Length > 0 Then clsSb.Append("\"c)
                    clsSb.Append(array(i))
                Next
                Return clsSb.ToString
            End Function

            Private Shared Function GetAll(ByVal share As Entities.Share, ByVal directoryCode As String, ByVal parts() As String, ByVal addedAfter As Date) As Reply
                Dim clsRet As Reply = CreateReplyObject(False)

                Dim clsGroup As New Group(Nothing, True)
                clsRet.Groups.Add(clsGroup)

                Dim aItems As Generic.List(Of Entities.SharedItem)
                If addedAfter = DateTime.MinValue Then
                    aItems = EntityHandlers.SharedItems.GetAllByShareId(share.Id)
                Else
                    aItems = EntityHandlers.SharedItems.GetAllByShareIdAndAddedAfter(share.Id, addedAfter)
                End If

                clsGroup.Items = ConvertToItemInfos(aItems)
                Return clsRet
            End Function
            Private Shared Function GetByFileSys(ByVal share As Entities.Share, ByVal directoryCode As String, ByVal parts() As String, ByVal addedAfter As Date) As Reply
                Dim clsRet As Reply = CreateReplyObject(False)

                Dim strCurrentSubDir As String = parts(0)
                Dim strRelativePath As String = String.Empty
                For i As Integer = 1 To parts.Length - 1
                    strCurrentSubDir = System.IO.Path.Combine(strCurrentSubDir, parts(i))
                    strRelativePath = System.IO.Path.Combine(strRelativePath, parts(i))
                Next

                Dim clsTG As New Group("Directories")
                For Each clsSub As Entities.Infos.DirectoryInfo In EntityHandlers.SharedItems.GetAllSubdirectoriesByShareIdAndRelativeDirectoryAsInfos(share.Id, strRelativePath)
                    Dim clsDir As New Directory(IO.Path.Combine(directoryCode, clsSub.Name), clsSub.Name)
                    clsDir.TotalItems = clsSub.TotalItems
                    clsDir.TotalSize = clsSub.TotalSize
                    clsTG.Directories.Add(clsDir)
                Next
                clsRet.Groups.Add(clsTG)

                Dim clsGroup As New Group("Items")
                clsRet.Groups.Add(clsGroup)

                Dim aItems As Generic.List(Of Entities.SharedItem)
                aItems = EntityHandlers.SharedItems.GetAllByShareIdAndRelativeDirectory(share.Id, strRelativePath)
                clsGroup.Items = ConvertToItemInfos(aItems)
                Return clsRet
            End Function
        End Class
    End Class

End Namespace